package com.jh.user.pojo;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;

@Entity
@Table(name = "t_store_info")
public class StoreInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    public static StoreInfo info(ShopRegister shopRegister) {
        String uuid = System.currentTimeMillis() + "" + new Random().nextInt();
        StoreInfo storeInfo = new StoreInfo();
        storeInfo.setUserId(shopRegister.getUserId());
        storeInfo.setShopId(shopRegister.getShopId());
        storeInfo.setShopName(shopRegister.getShopName());
        storeInfo.setProvince(shopRegister.getShopProvinces());
        storeInfo.setCity(shopRegister.getShopCity());
        storeInfo.setAdress(shopRegister.getShopAddress());
        storeInfo.setStoreNo(uuid);
        storeInfo.setStoreName(shopRegister.getShopName());
        /** 联系人 */
        storeInfo.setPeople(shopRegister.getShopUserName());
        /** 联系人手机号 */
        storeInfo.setPhone(shopRegister.getShopUserPhone());
        storeInfo.setEmail(shopRegister.getShopUserEmail());
        storeInfo.setCreateTime(Calendar.getInstance().getTime());
        return storeInfo;
    }

    public StoreInfo update(ShopRegister shopRegister) {
        setUserId(shopRegister.getUserId());
        setShopId(shopRegister.getShopId());
        setShopName(shopRegister.getShopName());
        setProvince(shopRegister.getShopProvinces());
        setCity(shopRegister.getShopCity());
        setAdress(shopRegister.getShopAddress());
        setStoreName(shopRegister.getShopName());
        /** 联系人 */
        setPeople(shopRegister.getShopUserName());
        /** 联系人手机号 */
        setPhone(shopRegister.getShopUserPhone());
        setEmail(shopRegister.getShopUserEmail());
        return this;
    }

    /**
     * 不需要更新的属性
     */
    public StoreInfo notUpdateProps() {
        setId(null);
        setStoreNo(null);
        setShopId(null);
        setShopName(null);
        setUserId(null);
        return this;
    }

    private Long id;
    private Long userId;
    private String shopId;
    private String shopName;
    private String province;
    private String city;
    private String adress;
    private String storeNo;
    private String storeName;
    private String people;
    private String phone;
    private String email;
    private Date createTime;


    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id
    @Column(name = "id")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Basic
    @Column(name = "user_id")
    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    @Basic
    @Column(name = "shop_id")
    public String getShopId() {
        return shopId;
    }

    public void setShopId(String shopId) {
        this.shopId = shopId;
    }

    @Basic
    @Column(name = "shop_name")
    public String getShopName() {
        return shopName;
    }

    public void setShopName(String shopName) {
        this.shopName = shopName;
    }

    @Basic
    @Column(name = "province")
    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    @Basic
    @Column(name = "adress")
    public String getAdress() {
        return adress;
    }

    public void setAdress(String adress) {
        this.adress = adress;
    }


    @Basic
    @Column(name = "city")
    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    @Basic
    @Column(name = "store_no")
    public String getStoreNo() {
        return storeNo;
    }

    public void setStoreNo(String storeNo) {
        this.storeNo = storeNo;
    }

    @Basic
    @Column(name = "store_name")
    public String getStoreName() {
        return storeName;
    }

    public void setStoreName(String storeName) {
        this.storeName = storeName;
    }

    @Basic
    @Column(name = "people")
    public String getPeople() {
        return people;
    }

    public void setPeople(String people) {
        this.people = people;
    }

    @Basic
    @Column(name = "phone")
    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Basic
    @Column(name = "email")
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Basic
    @Column(name = "create_time")
    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public boolean equalsV(StoreInfo o) {
        if (o == null || getClass() != o.getClass()) return false;
        if (o.getShopId() == null || "".equals(o.getShopId())) return false;

        if (o.getCity() == null || "".equals(o.getCity())) return false;

        if (o.getProvince() == null || "".equals(o.getProvince())) return false;

        if (o.getAdress() == null || "".equals(o.getAdress())) return false;

        if (o.getStoreName() == null || "".equals(o.getStoreName())) return false;

        if (o.getPeople() == null || "".equals(o.getPeople())) return false;
        if (o.getPhone() == null || "".equals(o.getPhone())) return false;
        if (o.getEmail() == null || "".equals(o.getEmail())) return false;

        return true;
    }


}
